Skip to content

fix: fall back when payload compression fails#700

Merged
marandaneto merged 4 commits into
mainfrom
fix/compression-failure-fallback
Jun 29, 2026
Merged

fix: fall back when payload compression fails#700
marandaneto merged 4 commits into
mainfrom
fix/compression-failure-fallback

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

When gzip=True, local gzip failures should not prevent the SDK from sending the batch. The SDK should fall back to the original uncompressed JSON payload without a Content-Encoding header.

This catches local gzip errors during request construction and keeps the upload path uncompressed. A unit test covers the fallback.

💚 How did you test it?

  • uv run --extra test pytest posthog/test/test_request.py -q

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented as part of a cross-SDK consistency pass for client-side compression failure fallback. Kept the change scoped to request construction and added a focused regression test.

@marandaneto marandaneto self-assigned this Jun 27, 2026
@greptile-apps

greptile-apps Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix: fall back when payload compression ..." | Re-trigger Greptile

Comment thread posthog/request.py Outdated
Comment thread posthog/test/test_request.py Outdated
@github-actions

github-actions Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-06-29 09:42:21 UTC
Duration: 530093ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 515ms
Format Validation.Event Has Uuid 10008ms
Format Validation.Event Has Lib Properties 10007ms
Format Validation.Distinct Id Is String 10007ms
Format Validation.Token Is Present 10007ms
Format Validation.Custom Properties Preserved 10007ms
Format Validation.Event Has Timestamp 10007ms
Retry Behavior.Retries On 503 18019ms
Retry Behavior.Does Not Retry On 400 12005ms
Retry Behavior.Does Not Retry On 401 10007ms
Retry Behavior.Respects Retry After Header 16013ms
Retry Behavior.Implements Backoff 30018ms
Retry Behavior.Retries On 500 13010ms
Retry Behavior.Retries On 502 16010ms
Retry Behavior.Retries On 504 16010ms
Retry Behavior.Max Retries Respected 30007ms
Deduplication.Generates Unique Uuids 7014ms
Deduplication.Preserves Uuid On Retry 16017ms
Deduplication.Preserves Uuid And Timestamp On Retry 23018ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 16005ms
Deduplication.No Duplicate Events In Batch 10003ms
Deduplication.Different Events Have Different Uuids 10007ms
Compression.Sends Gzip When Enabled 10007ms
Batch Format.Uses Proper Batch Structure 10007ms
Batch Format.Flush With No Events Sends Nothing 5005ms
Batch Format.Multiple Events Batched Together 10005ms
Error Handling.Does Not Retry On 403 12009ms
Error Handling.Does Not Retry On 413 10006ms
Error Handling.Retries On 408 14014ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 9502ms
Request Payload.Flags Request Uses V2 Query Param 10007ms
Request Payload.Flags Request Hits Flags Path Not Decide 10007ms
Request Payload.Flags Request Omits Authorization Header 10007ms
Request Payload.Token In Flags Body Matches Init 10007ms
Request Payload.Groups Round Trip 10007ms
Request Payload.Groups Default To Empty Object 10007ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 10007ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 10007ms
Request Payload.Disable Geoip Omitted Defaults To False 10006ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 10008ms
Request Lifecycle.No Flags Request On Init Alone 5003ms
Request Lifecycle.No Flags Request On Normal Capture 10507ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 9512ms
Request Lifecycle.Mock Response Value Is Returned To Caller 10002ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 10510ms

@marandaneto marandaneto marked this pull request as ready for review June 29, 2026 06:29
@marandaneto marandaneto requested a review from a team as a code owner June 29, 2026 06:29
@greptile-apps

greptile-apps Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Format compression fallback test" | Re-trigger Greptile

Comment thread posthog/request.py Outdated
@marandaneto marandaneto enabled auto-merge (squash) June 29, 2026 09:33
@marandaneto marandaneto merged commit cd86110 into main Jun 29, 2026
31 checks passed
@marandaneto marandaneto deleted the fix/compression-failure-fallback branch June 29, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants